package com.nervenets.web.hibernate.dao;

import com.nervenets.web.hibernate.domain.knowledge.Tags;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
public interface TagsDao extends JpaRepository<Tags, Long>, JpaSpecificationExecutor<Tags> {
    /**
     * 增加标签的权重
     *
     * @param tagsId
     */
    @Modifying
    @Transactional
    @Query(value = "update tags set weight = weight + 1 where id = ?1", nativeQuery = true)
    void weightAdd(long tagsId);

    /**
     * 查询所有启用的标签
     *
     * @param managerId
     * @return
     */
    List<Tags> findAllByManagerIdAndEnableIsTrueOrderByWeightDesc(long managerId);
}
